#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1e5+10;

int val[N<<2],n,q,a[N];

int gcd(int x,int y){return !y ? x : gcd(y,x%y);}

void build(int o = 1,int l = 1,int r = n){
	if(l == r) return val[o] = a[l],void();
	int mid = l+r>>1;build(o<<1,l,mid); build(o<<1|1,mid+1,r); val[o] = gcd(val[o<<1],val[o<<1|1]);
}

void upd(int pos,int v,int o = 1,int l = 1,int r = n){
	if(l == r) return val[o] = v,void();
	int mid = l+r>>1;if(pos <= mid) upd(pos,v,o<<1,l,mid);else upd(pos,v,o<<1|1,mid+1,r); val[o] = gcd(val[o<<1],val[o<<1|1]);
}

int find(int o = 1,int l = 1,int r = n,int pre = 0,int suf = 0){
	if(l == r) return l;
	int mid = l + r>>1,x = gcd(val[o<<1],pre),y = gcd(val[o<<1|1],suf);
	if(x <= y) return find(o<<1,l,mid,pre,y); else return find(o<<1|1,mid+1,r,x,suf);
}

ll QL(int pos,int o = 1,int l = 1,int r = n,int tot = 0){
	if(l == r) return gcd(val[o],tot);
	int mid = l+r>>1;
	if(pos <= mid) return QL(pos,o<<1,l,mid,gcd(tot,val[o<<1|1]));
	else{
		int x = gcd(val[o<<1|1],tot),y = gcd(x,val[o<<1]);
		return (x == y ? 1ll * (mid - l + 1) * x : QL(pos,o<<1,l,mid,x)) + QL(pos,o<<1|1,mid+1,r,tot);
	}
}

ll QR(int pos,int o = 1,int l = 1,int r = n,int tot = 0){
	if(l == r) return gcd(val[o],tot);
	int mid = l+r>>1;
	if(pos > mid) return QR(pos,o<<1|1,mid+1,r,gcd(tot,val[o<<1]));
	else{
		int x = gcd(val[o<<1],tot),y = gcd(x,val[o<<1|1]);
		return (x == y ? 1ll * (r - mid) * y : QR(pos,o<<1|1,mid+1,r,x)) + QR(pos,o<<1,l,mid,tot);
	}
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,q = in;
	for(int i = 1;i <= n;i++) a[i] = in;
	build();
	while(q--){
		int t = in,x = in;
		upd(t,x);
		int p = find();
		ll ans = QL(p) + QR(p) - val[1];printf("%lld\n",ans);
	}
	return 0;
}

